<template>
  <view>
    <view class="mySearch">
      <my-search @click='gotoSearch'></my-search>
    </view>
    <swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" class="swiper">
      <swiper-item v-for="item in swiperList" :key='item.goods_id'>
        <navigator :url='"/subpkg/goods_detail/goods_detail?goods_id="+item.goods_id' open-type="navigate" class="swiper-item">
          <image :src="item.image_src" mode="" class=".image"></image>
        </navigator>
      </swiper-item>
    </swiper>
    <view class="nav_list">
      <view class="nav_item" v-for="(item,index) in navList" :key='index' @click="navClickHanlder(item.name)">
        <image :src="item.image_src" mode="" class="nav_image"></image>
      </view>
    </view>
    <view class="floors">
      <view class="floor" v-for="(item,index) in floorList" :key='index'>
        <view class="title">
          <image :src="item.floor_title.image_src" mode="" class="image"></image>
        </view>
        <view class="main">
          <view class="left">
            <image :src="item.product_list[0].image_src" mode="widthFix" :style="{width:item.product_list[0].image_width+'rpx'}" @click="gotoList(item.product_list[0].navigator_url.split('/'))"></image>
          </view>
          <view class="right">
            <view class="right_imageItem" v-for="(item1,index1) in item.product_list" :key='index1' v-if="index1!==0">
              <image :src="item1.image_src" mode="widthFix" :style="{width:item1.image_width+'rpx'}" @click="gotoList(item1.navigator_url.split('/'))"></image>
            </view>
          </view>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
  import {reqSwiperList,reqNavList,reqFloorList} from '../../api/api.js';
  import tabbarMixin from '@/mixin/tabbar-badge.js';
  export default {
    mixins:[tabbarMixin],
    data() {
      return {
        swiperList:[],
        navList:[],
        floorList:[]
      };
    },
    onLoad() {
      this.getSwiperList();
      this.getNavList();
      this.getFloorList();
    },
    methods:{
      async getSwiperList(){
        let res= await reqSwiperList();
        if(res.data.meta.status===200){
          this.swiperList=res.data.message;
        }else{
          return uni.$showMsg();
        }
      },
      async getNavList(){
        let res=await reqNavList();
        if(res.data.meta.status===200){
          this.navList=res.data.message;
        }else{
          return uni.$showMsg();
        }
      },
      async getFloorList(){
        let res=await reqFloorList();
        if(res.data.meta.status===200){
          this.floorList=res.data.message;
        }else{
          return uni.$showMsg();
        }
      },
      navClickHanlder(name){
        if(name==='分类'){
          uni.switchTab({
            url:'/pages/cate/cate'
          })
        }
      },
      gotoList(query){
        uni.navigateTo({
          url:'/subpkg/goods_list/'+query[2]
        })
      },
      gotoSearch(){
        uni.navigateTo({
          url:'/subpkg/search/search'
        })
      }
    }
    
  }
</script>

<style lang="scss" scoped>
.mySearch{
  position: sticky;
  top: 0;
  z-index: 999;
}
// 轮播图
.swiper{
  height: 330rpx;
  .swiper-item,
  .image{
    width: 100%;
    height: 100%;
  }
}

// 分类导航
.nav_list{
  display: flex;
  justify-content: space-around;
  margin: 15rpx 0;
  .nav_image{
    width: 128rpx;
    height: 140rpx;
  }
}

// 楼层
.floors{
  .floor{
    margin-bottom: 20rpx;
    .title{
      .image{
        width: 100%;
        height: 60rpx;
      }
    }
    .main{
      display: flex;
      .right{
        margin-left: 10rpx;
        display: flex;
        flex-wrap: wrap;
        justify-content: space-around;
      }
    }
  }
}
</style>
